import request from '@/util/request'
import store from '@/vuex/store'
import config from '@/config/config'

//用户名密码验证获取token
export function getToken(loginForm) {
    return request({
        url: 'user/login/login.do',
        method: 'post',
        data: {
            username: loginForm.username,
            password: loginForm.password,
            jurisdiction: config.jurisdiction
        }
    })
}

//获取用户的router列表
export function getRouter(token) {
    return request({
        url: 'user/login/getRouter.do',
        method: 'post',
        data: {
            token: token
        }
    })
}

//获取所有用户数据
export function getUserData(list) {
    return request({
        url: 'user/info/getUserInfo.do',
        method: 'post',
        data: {
            pageSize: list.pageSize,
            currentPage: list.currentPage,
            token: store.getters.token
        }
    })
}

//添加用户数据
export function addUserInfo(list) {
    return request({
        url: 'user/info/addUserInfo.do',
        method: 'post',
        data: {
            userInfo: JSON.stringify(list),
            token: store.getters.token
        }
    })
}

//修改用户菜单
export function editUserMenu(list) {
    return request({
        url: 'user/info/editUserMenu.do',
        method: 'post',
        data: {
            userMenu: list,
            token: store.getters.token
        }
    })
}

//根据token获取用户信息
export function getUserInfoForToken() {
    return request({
        url: 'user/info/getUserInfoForToken.do',
        method: 'post',
        data: {
            token: store.getters.token
        }
    })
}
//根据当前用户的currentCode去
export function getUserInfoCurrentCode() {
    return request({
        url: 'user/info/getUserInfoCurrentCode.do',
        method: 'post',
        data: {
            token: store.getters.token,
            username: store.getters.username
        }
    })
}

//修改用户密码
export function editLoginPassword(LoginName, LoginPssword) {
    return request({
        url: 'user/info/editLoginPassword.do',
        method: 'post',
        data: {
            token: store.getters.token,
            LoginName: LoginName,
            LoginPssword: LoginPssword
        }
    })
}

//退出系统
export function getOutSysyem() {
    return request({
        url: '/outSystem',
        method: 'post',
        data: {
            token: store.getters.token
        }
    })
}


//查询所有账号id和名称
export function getUserOption() {
    return request({
        url: 'user/info/getUserOption.do',
        method: 'post',
        data: {
            token: store.getters.token
        }
    })
}

//条件查询用户
export function getUserByCondition(list) {
    const value = {
        pageSize: list.pageSize,
        currentPage: list.currentPage,
        appKey: '',
        appFlag: 2,
        token: store.getters.token,
        versionCode: 0,
        param: JSON.stringify(list)
    }
    return request({
        url: 'user/getUserByCondition.do',
        method: 'post',
        data: value
    })
}

//删除用户
export function removeUser(list) {
    const value = {
        appKey: '',
        appFlag: 2,
        token: store.getters.token,
        versionCode: 0,
        param: JSON.stringify(list)

    }
    return request({
        url: 'user/info/removeUser.do',
        method: 'post',
        data: value
    })
}

export function getUserAccount() {
    const value = {
        appKey: '',
        appFlag: 2,
        token: store.getters.token,
        versionCode: 0,
        param: store.getters.username
    }
    return request({
        url: 'user/info/getUserAccount.do',
        method: 'post',
        data: value
    })
}
export function checkPasswordApi(data) {
    const value = {
        appKey: '',
        appFlag: 2,
        token: store.getters.token,
        versionCode: 0,
        param: JSON.stringify(data)
    }
    return request({
        url: 'user/info/checkPassword.do',
        method: 'post',
        data: value
    })
}
//修改密码
export function editUserPasswordApi(data) {
    const value = {
        appKey: '',
        appFlag: 2,
        token: store.getters.token,
        versionCode: 0,
        param: JSON.stringify(data)
    }
    return request({
        url: 'user/info/editUserPasswordById.do',
        method: 'post',
        data: value
    })
}